package com.victor.common.constant.dictmap.factory;

import com.victor.common.constant.dictmap.base.AbstractDictMap;
import com.victor.common.constant.dictmap.base.SystemDict;
import com.victor.common.exception.BizExceptionEnum;
import com.victor.common.exception.BussinessException;

/**
 * 字典的创建工厂
 */
public class DictMapFactory {
    /**
     * BASE_PATH
     */
    private static final String BASE_PATH = "com.victor.common.constant.dictmap.";
    /**
     * SYSTEM_DICT
     */
    private static final String SYSTEM_DICT = "SystemDict";

    /**
     * <b>Description:通过类名创建具体的字典类</b><br>
     *
     * @param className
     * @return
     * @Note <b>Author:</b>zhaojiabin</a>
     * <br><b>Date:</b> 2017年10月18日 上午9:32:32
     * <br><b>Version:</b> 1.0
     */
    public static AbstractDictMap createDictMap(String className) {
        if (SYSTEM_DICT.equals(className)) {
            return new SystemDict();
        } else {
            try {
                Class<AbstractDictMap> clazz = (Class<AbstractDictMap>) Class.forName(BASE_PATH + className);
                return clazz.newInstance();
            } catch (Exception e) {
                throw new BussinessException(BizExceptionEnum.ERROR_CREATE_DICT);
            }
        }
    }
}
